import router from "./index";
import  {asyncRoutes,constantRoutes} from "./index";
const permission={
  state:{
    routers:constantRoutes,
    addRouters:[]
  },
  mutations: {
    setRouters: (state, routers) => {
      state.addRouters = routers;
      state.routers = constantRoutes.concat(routers);
    }
  },
  actions: {
    handleRoutes({ commit }, data) {
      console.log(data)
      let {status} =JSON.parse(data);
      console.log(status)
      return new Promise(resolve => {
        let addRoutes = []
        if (status === "专家") {
          addRoutes = asyncRoutes
          commit('setRouters', addRoutes)
          if (addRoutes.length) {
            console.log(addRoutes.length)
            router.addRoutes(addRoutes)
          }
        }
        resolve()
      })
    }
  }
    // action:{
    //     generateRoutes({commit},data){
    //       return new Promise(resolve => {
    //           const {status} =data;
    //           const accessedRouters=asyncRoutes.filter(item=>{
    //
    //           })
    //       })
    //     }
    //
    // }








}

export default permission
